﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.IO;



public partial class Default4 : System.Web.UI.Page
{
    string listingId;

    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {

            setControlValues();
        }
    }

    private void setControlValues()
    {

        if (Request.QueryString["EditListingId"] == null)
        {

            listingId = Request.QueryString["ListingId"].ToString();
            btnAddPhotosVideos.Attributes.Add("onclick", "window.open('ImageVideosUpload.aspx?ListingId=" + listingId + "', 'newwindow','toolbar=yes,location=no,menubar=no,width=700,height=500,resizable=yes,scrollbars=yes,top=150,left=150');return false;");
        }
        else
        {
            listingId = Request.QueryString["EditListingId"].ToString();
            btnAddPhotosVideos.Attributes.Add("onclick", "window.open('ImageVideosUpload.aspx?EditListingId=" + listingId + "', 'newwindow','toolbar=yes,location=no,menubar=no,width=700,height=500,resizable=yes,scrollbars=yes,top=150,left=150');return false;");
        }


        DataTable dtListing = new DataTable();
        dtListing = BuddyAgentDAL.GetParticularListingInfo(Convert.ToInt32(listingId));

        DataTable dtAgentProfile = new DataTable();
        dtAgentProfile = BuddyAgentDAL.GetBuddyAgentInfo(Convert.ToInt32(dtListing.Rows[0][1]));


        DataTable dtCurrentPreviousListing = new DataTable();
        dtCurrentPreviousListing = BuddyAgentDAL.GetCurrentPreviousListing(Convert.ToInt32(dtListing.Rows[0][1]));

        lblActiveListingCount.Text = "(" + dtCurrentPreviousListing.Rows[0][1].ToString() + ")";
        lblPreviousListingCount.Text = "(" + dtCurrentPreviousListing.Rows[0][2].ToString() + ")";

        DataSet dsAgentInformation = new DataSet();
        dsAgentInformation = BuddyAgentDAL.GetBuddyAgentInfoBasedOnFBId(dtAgentProfile.Rows[0][3].ToString());

        imgUsr.ImageUrl = dsAgentInformation.Tables[0].Rows[0][2].ToString();
        lblProfileMsg.Text = dsAgentInformation.Tables[0].Rows[0][1].ToString() + ".<br/><br/>";

        if (dsAgentInformation.Tables[0].Rows.Count != 0)
        {
            DateTime dt = DateTime.Parse(dsAgentInformation.Tables[0].Rows[0][5].ToString());

            lblProfileMes.Text = "Member Since " + dt.Year;
            lblFriends.Text = "I have " + dsAgentInformation.Tables[1].Rows[0][0].ToString() + " Friends.<br/>";
            lblProfileMes.Visible = true;
            lblFriends.Visible = true;
        }
    }

    protected void MovePostListing_Click(object sender, EventArgs e)
    {
        if (Request.QueryString["EditListingId"] == null)
        {

            listingId = Request.QueryString["ListingId"].ToString();
        }
        else
        {
            listingId = Request.QueryString["EditListingId"].ToString();
        }
        Response.Redirect("~/ParticularListingInformation.aspx?ListingId=" + listingId);
    }

    protected void linkActiveListing_Click(object sender, EventArgs e)
    {
        if (Request.QueryString["EditListingId"] == null)
        {

            listingId = Request.QueryString["ListingId"].ToString();
        }
        else
        {
            listingId = Request.QueryString["EditListingId"].ToString();
        }
        if (lblActiveListingCount.Text != "")
        {
            int listing = Convert.ToInt32(listingId);

            DataTable dtListingInfo = new DataTable();
            dtListingInfo = BuddyAgentDAL.GetParticularListingInfo(listing);

            int clientId = Convert.ToInt32(dtListingInfo.Rows[0][1]);

            Response.Redirect("~/Default.aspx?ClientId=" + clientId + "&Active=1");
        }
    }

    protected void linkPreviousListing_Click(object sender, EventArgs e)
    {
        if (Request.QueryString["EditListingId"] == null)
        {

            listingId = Request.QueryString["ListingId"].ToString();
        }
        else
        {
            listingId = Request.QueryString["EditListingId"].ToString();
        }
        if (lblPreviousListingCount.Text != "")
        {
            int listing = Convert.ToInt32(listingId);

            DataTable dtListingInfo = new DataTable();
            dtListingInfo = BuddyAgentDAL.GetParticularListingInfo(listing);

            int clientId = Convert.ToInt32(dtListingInfo.Rows[0][1]);

            Response.Redirect("~/Default.aspx?ClientId=" + clientId + "&Active=-1");
        }
    }

    protected void btnEditPost_Click(object sender, EventArgs e)
    {
        if (Request.QueryString["EditListingId"] == null)
        {

            listingId = Request.QueryString["ListingId"].ToString();
        }
        else
        {
            listingId = Request.QueryString["EditListingId"].ToString();
        }

        int listing = Convert.ToInt32(listingId);

        Response.Redirect("~/PostListingInformation.aspx?EditListingId=" + listing);
    }
}